#include "widget.h"
#include "ui_widget.h"

#include <QNetworkReply>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
    manager = new QNetworkAccessManager(this);
    connect(ui->pushButton, &QPushButton::clicked, this, [=](){
        QString url = ui->lineEdit->text();
        QNetworkRequest request(url);
        QNetworkReply* response = manager->get(request);
        connect(response, &QNetworkReply::readyRead, this, [=](){
            if(response->error() == QNetworkReply::NoError)
                {
                QString html = response->readAll();
                ui->plainTextEdit->setPlainText(html);
            }
            else
                {
                ui->plainTextEdit->setPlainText(response->errorString());
            }
            response->deleteLater();
        });
    });
}

Widget::~Widget()
{
    delete ui;
}
